﻿using System;
namespace Producers.Ehma10000000.Xtee.Riik.Ee.Producer.Ehma10000000 {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="tur2", Namespace="http://producers.ehma-10000000.xtee.riik.ee/producer/ehma-10000000", Target=typeof(Tur2))]
    public class Tur2Serializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected ITur2 clazz;
        
        public Tur2Serializer(ITur2 clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("tourid");
            if (clazz.Tourid!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tourid))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Tourid");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("tourname");
            if (clazz.Tourname!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tourname))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Tourname");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("orgform");
            if (clazz.Orgform!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Orgform))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Orgform");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("tourstart");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.Tourstart))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("tourend");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.Tourend))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("tourloc");
            if (clazz.Tourloc!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tourloc))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Tourloc");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("partno");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "nonNegativeInteger");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdNonNegativeInteger(((decimal)(clazz.Partno))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("poolam");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "decimal");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDecimal(((decimal)(clazz.Poolam))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("totalrake");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "decimal");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDecimal(((decimal)(clazz.Totalrake))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("pricepool");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "decimal");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDecimal(((decimal)(clazz.Pricepool))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("totalpayo");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "decimal");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDecimal(((decimal)(clazz.Totalpayo))).ToString());
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="tourid") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>tur2>tourid");
                }
                clazz.Tourid = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tourid")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>tur2>tourid", Reader.LocalName);
            }
            if (Reader.LocalName=="tourname") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>tur2>tourname");
                }
                clazz.Tourname = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tourname")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>tur2>tourname", Reader.LocalName);
            }
            if (Reader.LocalName=="orgform") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>tur2>orgform");
                }
                clazz.Orgform = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("orgform")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>tur2>orgform", Reader.LocalName);
            }
            if (Reader.LocalName=="tourstart") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>tur2>tourstart");
                }
                clazz.Tourstart = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("tourstart")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>tur2>tourstart", Reader.LocalName);
            }
            if (Reader.LocalName=="tourend") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>tur2>tourend");
                }
                clazz.Tourend = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("tourend")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>tur2>tourend", Reader.LocalName);
            }
            if (Reader.LocalName=="tourloc") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>tur2>tourloc");
                }
                clazz.Tourloc = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tourloc")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>tur2>tourloc", Reader.LocalName);
            }
            if (Reader.LocalName=="partno") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>tur2>partno");
                }
                clazz.Partno = new global::Xtee.Core.Schema.XsdNonNegativeInteger(Reader.ReadElementString("partno")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>tur2>partno", Reader.LocalName);
            }
            if (Reader.LocalName=="poolam") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>tur2>poolam");
                }
                clazz.Poolam = new global::Xtee.Core.Schema.XsdDecimal(Reader.ReadElementString("poolam")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>tur2>poolam", Reader.LocalName);
            }
            if (Reader.LocalName=="totalrake") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>tur2>totalrake");
                }
                clazz.Totalrake = new global::Xtee.Core.Schema.XsdDecimal(Reader.ReadElementString("totalrake")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>tur2>totalrake", Reader.LocalName);
            }
            if (Reader.LocalName=="pricepool") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>tur2>pricepool");
                }
                clazz.Pricepool = new global::Xtee.Core.Schema.XsdDecimal(Reader.ReadElementString("pricepool")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>tur2>pricepool", Reader.LocalName);
            }
            if (Reader.LocalName=="totalpayo") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>tur2>totalpayo");
                }
                clazz.Totalpayo = new global::Xtee.Core.Schema.XsdDecimal(Reader.ReadElementString("totalpayo")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>tur2>totalpayo", Reader.LocalName);
            }
        }
    }
}
